pac1811 2.2.0
Loading...
Searching...
No Matches
pac1811.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef PAC1811_H
29#define PAC1811_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define PAC1811_REG_REFRESH 0x00
74#define PAC1811_REG_CTRL 0x01
75#define PAC1811_REG_ACC_COUNT 0x02
76#define PAC1811_REG_VACC 0x03
77#define PAC1811_REG_VBUS 0x04
78#define PAC1811_REG_VSENSE 0x05
79#define PAC1811_REG_VBUS_AVG 0x06
80#define PAC1811_REG_VSENSE_AVG 0x07
81#define PAC1811_REG_VPOWER 0x08
82#define PAC1811_REG_VBUS_MIN 0x09
83#define PAC1811_REG_VBUS_MAX 0x0A
84#define PAC1811_REG_VSENSE_MIN 0x0B
85#define PAC1811_REG_VSENSE_MAX 0x0C
86#define PAC1811_REG_VPOWER_MIN 0x0D
87#define PAC1811_REG_VPOWER_MAX 0x0E
88#define PAC1811_REG_CTRL_LAT 0x0F
89#define PAC1811_REG_NEG_PWR_FSR_LAT 0x10
90#define PAC1811_REG_ALERT_STATUS 0x11
91#define PAC1811_REG_SMBUS_SETTINGS 0x12
92#define PAC1811_REG_NEG_PWR_FSR 0x13
93#define PAC1811_REG_REFRESH_G 0x14
94#define PAC1811_REG_REFRESH_V 0x15
95#define PAC1811_REG_SLOW 0x16
96#define PAC1811_REG_CTRL_ACT 0x17
97#define PAC1811_REG_NEG_PWR_FSR_ACT 0x18
98#define PAC1811_REG_SLOW_ALERT1 0x19
99#define PAC1811_REG_GPIO_ALERT2 0x1A
100#define PAC1811_REG_ACC_FULLNESS_LIMITS 0x1B
101#define PAC1811_REG_OC_LIMIT 0x1C
102#define PAC1811_REG_UC_LIMIT 0x1D
103#define PAC1811_REG_OP_WARNING_LIMIT 0x1E
104#define PAC1811_REG_OP_CRITICAL_LIMIT 0x1F
105#define PAC1811_REG_OV_LIMIT 0x20
106#define PAC1811_REG_UV_LIMIT 0x21
107#define PAC1811_REG_STEP_LIMIT 0x22
108#define PAC1811_REG_LIMIT_NSAMPLES 0x23
109#define PAC1811_REG_ALERT_ENABLE 0x24
110#define PAC1811_REG_ACCUMULATOR_COUNT_PRESET 0x25
111#define PAC1811_REG_ACCUMULATOR_PRESET 0x26
112#define PAC1811_REG_PRODUCT_ID 0xFD
113#define PAC1811_REG_MANUFACTURER_ID 0xFE
114#define PAC1811_REG_REVISION_ID 0xFF
115 // pac1811_reg
117
122
127
132#define PAC1811_FSR_UNIPOLAR 0
133#define PAC1811_FSR_BIPOLAR 1
134#define PAC1811_FSR_BIPOLAR_HALF 2
135
140#define PAC1811_R9_RSENSE 0.01
141#define PAC1811_VSENSE_MAX 0.1
142#define PAC1811_VSOURCE_MAX 42.0
143#define PAC1811_FSC ( PAC1811_VSENSE_MAX / PAC1811_R9_RSENSE )
144#define PAC1811_POWER_FSR ( PAC1811_FSC * PAC1811_VSOURCE_MAX )
145
150#define PAC1811_PRODUCT_ID 0x84
151#define PAC1811_MANUFACTURER_ID 0x54
152
158#define PAC1811_DEVICE_ADDRESS_GENERAL_CALL 0x00
159#define PAC1811_DEVICE_ADDRESS_A1A0_GND_GND 0x40
160#define PAC1811_DEVICE_ADDRESS_A1A0_GND_VCC 0x41
161#define PAC1811_DEVICE_ADDRESS_A1A0_VCC_GND 0x44
162#define PAC1811_DEVICE_ADDRESS_A1A0_VCC_VCC 0x45
163#define PAC1811_DEVICE_ADDRESS_A1A0_SDA_GND 0x48
164#define PAC1811_DEVICE_ADDRESS_A1A0_SDA_VCC 0x49
165#define PAC1811_DEVICE_ADDRESS_A1A0_SCL_GND 0x4C
166#define PAC1811_DEVICE_ADDRESS_A1A0_SCL_VCC 0x4D
167 // pac1811_set
169
174
179
184#define PAC1811_MAP_MIKROBUS( cfg, mikrobus ) \
185 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
186 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
187 cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
188 cfg.a1_pin = MIKROBUS( mikrobus, MIKROBUS_PWM );
189 // pac1811_map // pac1811
192
197typedef struct
198{
199 uint32_t acc_count;
200 uint32_t acc_data_msb;
201 uint32_t acc_data_lsb;
202 float vbus;
203 float isense;
204 float vbus_avg;
206 float power;
207 float vbus_min;
208 float vbus_max;
211 float power_min;
212 float power_max;
213
215
220typedef struct
221{
222 // Output pins
223 digital_out_t pwr;
224
225 // Input pins
226 digital_in_t a1_pin;
227
228 // Modules
229 i2c_master_t i2c;
230
231 // I2C slave address
233
234 uint8_t vsense_fsr;
235 uint8_t vbus_fsr;
236
237} pac1811_t;
238
243typedef struct
244{
245 pin_name_t scl;
246 pin_name_t sda;
247
248 pin_name_t pwr;
249 pin_name_t a1_pin;
250
251 uint32_t i2c_speed;
252 uint8_t i2c_address;
253
255
260typedef enum
261{
264
266
272
283
298
312
324err_t pac1811_send_byte ( pac1811_t *ctx, uint8_t data_in );
325
337err_t pac1811_receive_byte ( pac1811_t *ctx, uint8_t *data_out );
338
351err_t pac1811_write_byte ( pac1811_t *ctx, uint8_t reg, uint8_t data_in );
352
365err_t pac1811_read_byte ( pac1811_t *ctx, uint8_t reg, uint8_t *data_out );
366
381err_t pac1811_block_write ( pac1811_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
382
397err_t pac1811_block_read ( pac1811_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
398
411
421
431
442
454
467
480
493err_t pac1811_set_fsr ( pac1811_t *ctx, uint8_t vsense_fsr, uint8_t vbus_fsr );
494
509
510#ifdef __cplusplus
511}
512#endif
513#endif // PAC1811_H
514 // pac1811
516
517// ------------------------------------------------------------------------ END
err_t pac1811_init(pac1811_t *ctx, pac1811_cfg_t *cfg)
PAC1811 initialization function.
err_t pac1811_block_write(pac1811_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
PAC1811 write registers function.
void pac1811_enable_device(pac1811_t *ctx)
PAC1811 enable device function.
err_t pac1811_read_byte(pac1811_t *ctx, uint8_t reg, uint8_t *data_out)
PAC1811 read register function.
err_t pac1811_set_fsr(pac1811_t *ctx, uint8_t vsense_fsr, uint8_t vbus_fsr)
PAC1811 set full-scale ranges function.
void pac1811_cfg_setup(pac1811_cfg_t *cfg)
PAC1811 configuration object setup function.
err_t pac1811_receive_byte(pac1811_t *ctx, uint8_t *data_out)
PAC1811 receive single byte function.
err_t pac1811_write_byte(pac1811_t *ctx, uint8_t reg, uint8_t data_in)
PAC1811 write register function.
err_t pac1811_refresh_global(pac1811_t *ctx)
PAC1811 global refresh function.
err_t pac1811_check_communication(pac1811_t *ctx)
PAC1811 communication check function.
err_t pac1811_send_byte(pac1811_t *ctx, uint8_t data_in)
PAC1811 send single byte function.
err_t pac1811_block_read(pac1811_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
PAC1811 read registers function.
err_t pac1811_default_cfg(pac1811_t *ctx)
PAC1811 default configuration function.
err_t pac1811_refresh_wo_acc_reset(pac1811_t *ctx)
PAC1811 refresh without accumulator reset function.
err_t pac1811_refresh(pac1811_t *ctx)
PAC1811 refresh function.
void pac1811_disable_device(pac1811_t *ctx)
PAC1811 disable device function.
uint8_t pac1811_get_a1_pin(pac1811_t *ctx)
PAC1811 get A1 pin function.
err_t pac1811_read_data(pac1811_t *ctx, pac1811_data_t *data_out)
PAC1811 read measurement data function.
pac1811_return_value_t
PAC1811 Click return value data.
Definition pac1811.h:261
@ PAC1811_ERROR
Definition pac1811.h:263
@ PAC1811_OK
Definition pac1811.h:262
PAC1811 Click configuration object.
Definition pac1811.h:244
uint32_t i2c_speed
Definition pac1811.h:251
pin_name_t pwr
Definition pac1811.h:248
pin_name_t scl
Definition pac1811.h:245
pin_name_t a1_pin
Definition pac1811.h:249
pin_name_t sda
Definition pac1811.h:246
uint8_t i2c_address
Definition pac1811.h:252
PAC1811 Click data object.
Definition pac1811.h:198
uint32_t acc_data_msb
Definition pac1811.h:200
float power_min
Definition pac1811.h:211
float isense_avg
Definition pac1811.h:205
float vbus_avg
Definition pac1811.h:204
float isense
Definition pac1811.h:203
float vbus_min
Definition pac1811.h:207
uint32_t acc_count
Definition pac1811.h:199
float vbus_max
Definition pac1811.h:208
float vbus
Definition pac1811.h:202
uint32_t acc_data_lsb
Definition pac1811.h:201
float power_max
Definition pac1811.h:212
float isense_min
Definition pac1811.h:209
float power
Definition pac1811.h:206
float isense_max
Definition pac1811.h:210
PAC1811 Click context object.
Definition pac1811.h:221
digital_out_t pwr
Definition pac1811.h:223
uint8_t vsense_fsr
Definition pac1811.h:234
digital_in_t a1_pin
Definition pac1811.h:226
i2c_master_t i2c
Definition pac1811.h:229
uint8_t vbus_fsr
Definition pac1811.h:235
uint8_t slave_address
Definition pac1811.h:232